<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入车辆名称" clearable style="width: 240px;" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
      <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleView()"
        class="manage-add-btn">添加车辆分类</el-button>
    </el-form>
    <el-table ref="tables" v-loading="loading" :data="list">
      <el-table-column label="分类名称" align="center" prop="className" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" style="color: #f56c6c;" @click="handleDelete(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 操作日志详细 -->
    <el-dialog :title='title' :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-form-item label="分类名称：" prop="className" style="width: 60%;">
          <el-input v-model="form.className" type="text" placeholder="请输入车辆名称"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit()">提 交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { carClassifylist, addClassify, delClassify } from "@/api/system/car";

export default {
  name: "vehice",
  data() {
    return {
      title: '添加车辆分类',
      editId: null,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: { className: '' },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志 */
    getList() {
      this.loading = true;
      carClassifylist(this.queryParams).then(response => {
        this.list = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.pageNum = 1;
    },
    /** 详细按钮操作 */
    handleView() {
      this.open = true;
    },
    handleDelete(ids) {
      delClassify(ids).then(response => {
        this.$modal.msgSuccess("删除成功");
        this.getList();
      });
    },
    submit() {
      if (!this.form.className) {
        return this.$message.error(`名称不能为空！`);
      }
      addClassify(this.form).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.open = false;
        this.getList();
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.manage-add-btn {
  float: right;
}

.uploadimage {
  width: 120px;
  height: 120px;
}
</style>
